package com.arrays;

public class Sqrtx0123_69 {
    public int mySqrt(int x) {
        if(x<=1) return x;
        long right = x/2,left = 0;

        while (left<=right){
            long mid = (right+left) >> 1;
            long mul = mid * mid;
            if(mul == x) return (int)mid;
            if(mul > x) right = mid-1;
            if(mul < x) left = mid+1;
        }
        return (int)right;
    }

}
